import * as CONSTANT from '../constants'
import { fromJS } from 'immutable'
import { baseURL,baseWSURL } from '../../network/request'
import defaultimg from '../../statics/img/logo.png'
import error_img from '../../statics/img/neterr.svg'


const defaultState = fromJS({
    usr : "",
    identity: "",
    verifycodeurl: baseURL + 'user/code',
    avatar : defaultimg,
    
    
    
    
})
  

//eslint-disable-next-line
export default (state = defaultState ,action) => {
    switch (action.type) {
        case CONSTANT.ERRORCODE:
            return state.set('verifycodeurl',error_img)


        case CONSTANT.REFRESHIMG:
            return state.set('verifycodeurl',baseURL+ '/user/code?'+ Math.random())
        case  CONSTANT.SETUSR:
            return state.merge({
                usr:action.username,
                identity:action.identity,
                avatar:action.avatar,
                ws_url: baseWSURL + action.username
            })
        
        case CONSTANT.SETAVATAR:
            return state.set('avatar',action.avatar)
        default:
            return state
            
    }
}